<?php

FILESAVER;

/**
 * Description of View
 *
 * @author adrian
 */
class View {

    private $_data = array();
    private $_file;

    public function __construct($filename) {
        $this->_file = System::search($filename, 'views');
    }

    /**
     *
     * @param string $filename
     * @return View
     */
    public static function factory($filename) {
        return new View($filename);
    }

    /**
     *
     * @param mixed $name
     * @param mixed $value
     */
    public function __set($name, $value) {
        $this->_data[$name] = $value;
//        print_r($this->_data);
    }

    /**
     *
     * @param mixed $name
     * @return mixed
     */
    public function &__get($name) {
//        print_r($this->_data);
        return $this->_data[$name];
    }

    /**
     *
     * @param sitring $file_view
     */
    public function load_view() {
        ob_start();
        extract($this->_data);
        include $this->_file;
        return ob_get_clean();
    }

    /**
     *
     * @return String
     */
    public function render() {
        $output = $this->load_view();
        echo $output;
    }

}
?>
